package com.cxmx.escort.base;/**
 * @ClassName:Result
 * @Description //TODO
 * @Author chenyunxuan
 * @Date $ $
 **/

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Map;
import java.util.Objects;

/**
 * @ClassName:Result
 * @Description //TODO
 * @Author chenyunxuan
 * @Date $ $
 **/
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "统一返回类", description = "统一返回类")
public class Result<T> {
    private static Map<Integer, String> messageMap = Maps.newHashMap();

    /**
     * 程序定义状态码
     */

    @ApiModelProperty(value = "返回状态码")
    private int code;
    /**
     * 必要的提示信息
     */
    @ApiModelProperty(value = "描述信息")
    private String msg;
    /**
     * 业务数据
     */
    @ApiModelProperty(value = "返回数据")
    private T data;

    /**
     * 对业务数据单独处理
     *
     * @return
     */
    @Override
    public String toString() {
        if (Objects.isNull(this.data)) {
            this.setData(null);
        }
        return JSON.toJSONString(this);
    }
}
